<template>
	<div class="paper-wrap">
		<n-card>
			<!-- 学生信息 -->
			<div class="paper-title">
				<h2>用分光计测光波波长</h2>
				<div class="stu-info">
					<div class="stu-info-item">
						<span>学号：</span>
						<span>{{ sid }}</span>
					</div>
					<div class="stu-info-item">
						<span>姓名：</span>
						<span>{{ name }}</span>
					</div>
					<div class="stu-info-item">
						<span>班级：</span>
						<span>{{ college }}学院 {{ major }}专业 {{ grade }}级 {{ classnum }} 班</span>
					</div>
				</div>
			</div>
			<!-- 实验的基本信息 -->
			<n-divider title-placement="left">
				<h2>一、实验目的</h2>
			</n-divider>
			<div class="paper-purpose">
				<ol>
					<li> 1.了解分光计的原理和构造。 </li>
					<li> 2.观察光栅的衍射光谱，理解光栅衍射的原理 </li>
					<li>3.学会用光栅测定光波波长。</li>
				</ol>
			</div>
			<n-divider title-placement="left">
				<h2>二、实验仪器</h2>
			</n-divider>
			<div class="paper-instrument">
				<p class="instruments">本实验所用实验仪器有分光计、钠灯、汞灯、光栅等。
				</p>
			</div>
			<n-divider title-placement="left">
				<h2>三、实验原理</h2>
			</n-divider>
			<div class="paper-principle">
				<p class="principles"> 具体内容请参照实验指导书进行学习 </p>
			</div>

			<n-divider title-placement="left">
				<h2>四、数据记录与处理</h2>
			</n-divider>
			<div class="paper-data">
				<!-- 第一个表单 -->
				<el-form :form="model" style="font-size: 19px" label-width="160px" label-position="left">
					<el-form-item label="光栅刻痕数n=" style="width: 35%">
						<span style="font-size: 16px">{{ model[0].value }}</span>&emsp;<span style="font-size: 12px">{{ model[0].timeStamp }}</span>
					</el-form-item>

					<el-form-item label="光棚常数d=" style="width: 35%">
						<span style="font-size: 16px">{{ model[1].value }}</span>&emsp;<span style="font-size: 12px">{{ model[1].timeStamp }}</span>
					</el-form-item>
				</el-form>
				<h4 style="text-align: center">利用光栅衍射测量光波波长数据</h4>

				<table border="1" style="
						width: 100%;
						border-collapse: collapse;
						border: 1px solid #000;
					">
					<tr style="background: rgb(0, 0, 0, 0.1)">
						<td rowspan="3">条纹颜色</td>
						<td rowspan="3">级数</td>
						<td colspan="3">明纹位置</td>
						<td rowspan="3">平均值</td>
						<td rowspan="3">波长/cm</td>
						<td rowspan="3"> r/nm</td>
						<td rowspan="3">平均波长/nm</td>
					</tr>
					<tr>
						<td rowspan="2">左右明纹</td>
						<td colspan="2">两游标处读数</td>
					</tr>
					<tr>
						<td>左O</td>
						<td>右O</td>
					</tr>
					<tr>
						<td rowspan="4">钠灯黄色</td>
						<td>1</td>
						<td>左</td>
						<td>O1</td>
						<td>O1.</td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[2].value }}</span>&emsp;<span style="font-size: 12px">{{ model[2].timeStamp }}</span></td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[3].value }}</span>&emsp;<span style="font-size: 12px">{{ model[3].timeStamp }}</span></td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[4].value }}</span>&emsp;<span style="font-size: 12px">{{ model[4].timeStamp }}</span></td>
						<td rowspan="4"><span style="font-size: 16px">{{ model[5].value }}</span>&emsp;<span style="font-size: 12px">{{ model[5].timeStamp }}</span></td>
					</tr>
					<tr>
						<td>1</td>
						<td>右</td>
						<td>O(-1)</td>
						<td>O(-1).</td>
					</tr>
					<tr>
						<td>2</td>
						<td>左</td>
						<td>O2</td>
						<td>O2.</td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[6].value }}</span>&emsp;<span style="font-size: 12px">{{ model[6].timeStamp }}</span></td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[7].value }}</span>&emsp;<span style="font-size: 12px">{{ model[7].timeStamp }}</span></td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[8].value }}</span>&emsp;<span style="font-size: 12px">{{ model[8].timeStamp }}</span></td>
					</tr>
					<tr>
						<td>2</td>
						<td>右</td>
						<td>O(-2)</td>
						<td>O(-2).</td>
					</tr>
					<!-- 紫色 -->
					<tr>
						<td rowspan="4">汞灯紫色</td>
						<td>1</td>
						<td>左</td>
						<td>O1</td>
						<td>O1.</td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[9].value }}</span>&emsp;<span style="font-size: 12px">{{ model[9].timeStamp }}</span></td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[10].value }}</span>&emsp;<span style="font-size: 12px">{{ model[20].timeStamp }}</span></td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[11].value }}</span>&emsp;<span style="font-size: 12px">{{ model[11].timeStamp }}</span></td>
						<td rowspan="4"><span style="font-size: 16px">{{ model[12].value }}</span>&emsp;<span style="font-size: 12px">{{ model[12].timeStamp }}</span></td>
					</tr>
					<tr>
						<td>1</td>
						<td>右</td>
						<td>O(-1)</td>
						<td>O(-1).</td>
					</tr>
					<tr>
						<td>2</td>
						<td>左</td>
						<td>O2</td>
						<td>O2.</td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[13].value }}</span>&emsp;<span style="font-size: 12px">{{ model[13].timeStamp }}</span></td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[14].value }}</span>&emsp;<span style="font-size: 12px">{{ model[14].timeStamp }}</span></td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[15].value }}</span>&emsp;<span style="font-size: 12px">{{ model[15].timeStamp }}</span></td>
					</tr>
					<tr>
						<td>2</td>
						<td>右</td>
						<td>O(-2)</td>
						<td>O(-2).</td>
					</tr>
					<!-- 蓝紫色 -->
					<tr>
						<td rowspan="4">汞灯蓝紫色</td>
						<td>1</td>
						<td>左</td>
						<td>O1</td>
						<td>O1.</td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[16].value }}</span>&emsp;<span style="font-size: 12px">{{ model[16].timeStamp }}</span></td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[17].value }}</span>&emsp;<span style="font-size: 12px">{{ model[17].timeStamp }}</span></td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[18].value }}</span>&emsp;<span style="font-size: 12px">{{ model[18].timeStamp }}</span></td>
						<td rowspan="4"><span style="font-size: 16px">{{ model[19].value }}</span>&emsp;<span style="font-size: 12px">{{ model[19].timeStamp }}</span></td>
					</tr>
					<tr>
						<td>1</td>
						<td>右</td>
						<td>O(-1)</td>
						<td>O(-1).</td>
					</tr>
					<tr>
						<td>2</td>
						<td>左</td>
						<td>O2</td>
						<td>O2.</td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[20].value }}</span>&emsp;<span style="font-size: 12px">{{ model[20].timeStamp }}</span></td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[21].value }}</span>&emsp;<span style="font-size: 12px">{{ model[21].timeStamp }}</span></td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[22].value }}</span>&emsp;<span style="font-size: 12px">{{ model[22].timeStamp }}</span></td>
					</tr>
					<tr>
						<td>2</td>
						<td>右</td>
						<td>O(-2)</td>
						<td>O(-2).</td>
					</tr>
					<!-- 绿色 -->
					<tr>
						<td rowspan="4">汞灯绿色</td>
						<td>1</td>
						<td>左</td>
						<td>O1</td>
						<td>O1.</td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[23].value }}</span>&emsp;<span style="font-size: 12px">{{ model[23].timeStamp }}</span></td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[24].value }}</span>&emsp;<span style="font-size: 12px">{{ model[24].timeStamp }}</span></td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[25].value }}</span>&emsp;<span style="font-size: 12px">{{ model[25].timeStamp }}</span></td>
						<td rowspan="4"><span style="font-size: 16px">{{ model[26].value }}</span>&emsp;<span style="font-size: 12px">{{ model[26].timeStamp }}</span></td>
					</tr>
					<tr>
						<td>1</td>
						<td>右</td>
						<td>O(-1)</td>
						<td>O(-1).</td>
					</tr>
					<tr>
						<td>2</td>
						<td>左</td>
						<td>O2</td>
						<td>O2.</td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[27].value }}</span>&emsp;<span style="font-size: 12px">{{ model[27].timeStamp }}</span></td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[28].value }}</span>&emsp;<span style="font-size: 12px">{{ model[28].timeStamp }}</span></td>
						<td rowspan="2"><span style="font-size: 16px">{{ model[29].value }}</span>&emsp;<span style="font-size: 12px">{{ model[29].timeStamp }}</span></td>
					</tr>
					<tr>
						<td>2</td>
						<td>右</td>
						<td>O(-2)</td>
						<td>O(-2).</td>
					</tr>
				</table>
			</div>
			<!-- 第五个表单 -->
			<n-divider title-placement="left">
				<h2>五、实验分析</h2>
			</n-divider>
			<div class="paper-analyze">
				<!-- <div style="margin-bottom: 10px; font-size: 17px"
					>1.光波波长越长，经光栅衍射后对应的衍射角越（大或小）?</div
				>
				<el-input
					type="textarea"
					v-model="model[45].value"
					style="height: 100px"
					@blur="getTime(45)"
				/> -->
				<el-form-item label="1.光波波长越长，经光栅衍射后对应的衍射角越（大或小）?" style="width: 50%">
					<span style="font-size: 16px">{{ model[30].value }}</span>&emsp;<span style="font-size: 12px">{{ model[30].timeStamp }}</span>
				</el-form-item>
				<div style="margin-bottom: 10px; font-size: 17px">2. 请扫描课本附表2-8、附表2-9 二维码，查阅元素钠 (Na)
					谱线波长、汞(Hg)
					发射光谱对照自己的测量结果，分析误差产生的可能原因:</div>
				<span style="font-size: 16px">{{ model[31].value }}</span>&emsp;<span style="font-size: 12px">{{ model[31].timeStamp }}</span>
			</div>
			<div class="button" style="display: flex">
				<el-button type="primary" @click="exOk()">通过</el-button>
				<el-button type="success" @click="exFix()">需要修改</el-button>
			</div>
		</n-card>
	</div>
</template>
<script setup lang="ts">
//@ts-nocheck
// 关闭ts检查
import { useRoute } from 'vue-router'
import { getDetailEx, changeState } from '@/api/request'
import { useGlobalStore } from "../../../store/GlobalStore";
const route = useRoute()
// 试卷头的基本信息
// 使用onMounted生命周期函数
const jwtToken = localStorage.getItem('jwtToken')

onMounted(() => {
	getDetailEx(jwtToken, eid, rid).then((res) => {
		console.log(res.data.data[0], 'socket数据')
		model.value.forEach((element) => {
			var obj = element
			var kid = obj.kid
			if (res.data.data[0].hasOwnProperty(kid)) {
				obj.value = res.data.data[0][kid]
				obj.timeStamp = res.data.data[0]['t' + kid]
			}
		})
		console.log('处理后', model.value)
	})
})
const store=useGlobalStore()
const sid = route.query.sid
const rid = route.query.rid
const eid = route.query.eid
const name = route.query.name
const classnum = route.query.classNum
const college = route.query.college
const grade = route.query.grade
const major = route.query.major
const tid=store.userInfo.tid
const ws = new WebSocket(`ws://210.44.37.172:8082/message?id=${tid}&role=teacher`)
ws.onopen = function (e) {
	console.log('连接成功')
}
ws.onmessage = function (e) {
	console.log(e.data, '接收返回的消息')
	console.log(JSON.parse(e.data), '解析一下的数据')
	if (JSON.parse(e.data).rid == rid) {
		model.value.forEach((element) => {
			if (element.kid == JSON.parse(e.data).kid) {
				element.value = JSON.parse(e.data).value
				element.timeStamp = JSON.parse(e.data).timeStamp
			}
		})
	}
}
ws.onclose = function () {
	console.log('连接关闭')
}
ws.onerror = function () {
	console.log('连接出错')
}
// 学生填的值
// 实验通过
const exOk = () => {
	changeState(jwtToken, rid, 3).then((res) => {
		console.log(res)
		console.log("rid", rid);

		ElMessage.success('已通过')
	})
}
const exFix = () => {
	changeState(jwtToken, rid, 1).then((res) => {
		console.log(res)
		ElMessage.success('反馈成功')
	})
}


const model = ref([
	{ kid: 'k1', value: '', timeStamp: '' },
	{ kid: 'k2', value: '', timeStamp: '' },

	{ kid: 'k3_1', value: '', timeStamp: '' },
	{ kid: 'k3_2', value: '', timeStamp: '' },
	{ kid: 'k3_3', value: '', timeStamp: '' },
	{ kid: 'k3_4', value: '', timeStamp: '' },
	{ kid: 'k4_1', value: '', timeStamp: '' },
	{ kid: 'k4_2', value: '', timeStamp: '' },
	{ kid: 'k4_3', value: '', timeStamp: '' },
	{ kid: 'k5_1', value: '', timeStamp: '' },
	{ kid: 'k5_2', value: '', timeStamp: '' },
	{ kid: 'k5_3', value: '', timeStamp: '' },
	{ kid: 'k5_4', value: '', timeStamp: '' },
	{ kid: 'k6_1', value: '', timeStamp: '' },
	{ kid: 'k6_2', value: '', timeStamp: '' },
	{ kid: 'k6_3', value: '', timeStamp: '' },

	{ kid: 'k7_1', value: '', timeStamp: '' },
	{ kid: 'k7_2', value: '', timeStamp: '' },
	{ kid: 'k7_3', value: '', timeStamp: '' },
	{ kid: 'k7_4', value: '', timeStamp: '' },
	{ kid: 'k8_1', value: '', timeStamp: '' },
	{ kid: 'k8_2', value: '', timeStamp: '' },
	{ kid: 'k8_3', value: '', timeStamp: '' },

	{ kid: 'k9_1', value: '', timeStamp: '' },
	{ kid: 'k9_2', value: '', timeStamp: '' },
	{ kid: 'k9_3', value: '', timeStamp: '' },
	{ kid: 'k9_4', value: '', timeStamp: '' },

	{ kid: 'k10_1', value: '', timeStamp: '' },
	{ kid: 'k10_2', value: '', timeStamp: '' },
	{ kid: 'k10_3', value: '', timeStamp: '' },

	{ kid: 'k11', value: '', timeStamp: '' },
	{ kid: 'k12', value: '', timeStamp: '' },
	// ["kid":"value", "t"+"kid":"timeS",]
])

</script>

<style lang="less" scoped>
.paper-title {
	.stu-info {
		display: flex;
		align-items: center;

		.stu-info-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin: 10px;
		}
	}
}

.form1 {
	.form-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 10px;

		.input-group {
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 100%;

			.input {
				width: 100%;
			}
		}
	}
}

table {
	margin: 10px;

	tr {
		td {
			text-align: center;
			padding: 10px;

			input {
				width: 100%;
				height: 100%;
				border: none;
				outline: none;
				text-align: center;
				box-sizing: border-box;

				&:focus {
					border-radius: 5px;
					border: 1px solid #000;
				}
			}
		}
	}
}

.btn-group {
	// 右下角
	display: flex;
	align-items: flex-end;
	justify-content: flex-end;
	margin: 10px;

	.n-button {
		margin-left: 10px;
	}
}
</style>
